<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/4/29
 * Time: 15:54
 */
include_once("lib/api/src/CorpAPI.class.php");

include_once("lib/api/src/ServiceCorpAPI.class.php");
include_once("lib/api/src/ServiceProviderAPI.class.php");
$config = include_once('lib/weworkapi_php-master/config.php');
// 实例化 API 类
$api = new CorpAPI($corpId = 'ww55ca070cb9b7eb22', $secret = 'ktmzrVIlUH0UW63zi7-JyzsgTL9NfwUhHde6or6zwQY');

try {
    // 创建 User
    $user = new User();
    {
        $user->userid = "userid";
        $user->name = "name";
        $user->mobile = "131488888888";
        $user->email = "sbzhu@ipp.cas.cn";
        $user->department = array(1);
    }
    $api->UserCreate($user);

    // 获取User
    $user = $api->UserGet("userid");

    var_dump($user);
    // 删除User
//    $api->UserDelete("userid");
} catch(Exception $e) {
    echo $e->getMessage() . "\n";
//    $api->UserDelete("userid");
}



$agentId = $config['APP_ID'];
$api = new CorpAPI($config['CORP_ID'], $config['APP_SECRET']);
try {
    //
    $message = new Message();
    {
        $message->sendToAll = false;
        $message->touser = array("1710004");
//        $message->toparty = array(1, 2, 1111, 3333);
//        $message->totag= array(3, 4, 22233332, 33334444);
        $message->agentid = $agentId;
        $message->safe = 0;

        $message->messageContent = new NewsMessageContent(
            array(
                new NewsArticle(
                    $title = "Got you !",
                    $description = "Who's this cute guy testing me ?",
                    $url = "https://work.weixin.qq.com/wework_admin/ww_mt/agenda",
                    $picurl = "https://p.qpic.cn/pic_wework/167386225/f9ffc8f0a34f301580daaf05f225723ff571679f07e69f91/0",
                    $btntxt = "btntxt"
                ),
            )
        );
    }
    $invalidUserIdList = null;
    $invalidPartyIdList = null;
    $invalidTagIdList = null;

    $api->MessageSend($message, $invalidUserIdList, $invalidPartyIdList, $invalidTagIdList);
    var_dump($invalidUserIdList);
    var_dump($invalidPartyIdList);
    var_dump($invalidTagIdList);
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}